//validate----------------------------
//判断字符串是否为空
function isEmpty(strVal) {
    if (strVal == '' || strVal == null || strVal == undefined) {
        return true;
    } else {
        return false;
    }
}

function validate_mobile() {
    var value = $("#mobile").val();
    var pattern = /^(0?(13|14|15|18)[0-9]{9})$/;
    if(isEmpty(value) || !pattern.test(value)){
    	$("#mobile-err").html("手机号格式不正确");
    	$("#err").html("手机号格式不正确");
    	$("#err-info").css("display","block");
        return false;
    }else{
    	$("#err-info").css("display","none");
    	$("#mobile-err").html("");
        return true;
    }
}

function validate_pwd() {
    var value = $("#pwd").val();
    var pattern = /^([0-9a-zA-Z]{6,16})$/;
    if(isEmpty(value) || !pattern.test(value)){
    	$("#err").html("密码格式不正确");
    	$("#err-info").css("display","block");
    	$("#pwd-err").html("密码格式不正确");
        return false;
    }else{
    	$("#err-info").css("display","none");
    	$("#pwd-err").html("");
        return true;
    }
}

function validate_cpwd() {
    var cpwd = $("#pwd").val();
    var value = $("#cpwd").val();
    
    if(cpwd != value){
    	$("#err").html("两次密码输入不一致");
    	$("#err-info").css("display","block");
        return false;
    }else{
    	$("#err-info").css("display","none");
        return true;
    }
}

function validate_code() {
	var res = "";
    var value = $("#code").val();
    if(isEmpty(value)){
    	$("#err").html("图形验证码为空");
    	$("#err-info").css("display","block");
    	$("#code-err").html("图形验证码为空");
        return false;
    }else{
    	$.ajax({
    		url: "imgCode/validate?code="+value,
    		data: {},
    		dataType: 'json',
    		type: "GET",
    		async:false,
    		success: function (result) {  
    			res = result;
            	if(result.status != 200){
            		$("#err").html("图形验证码错误");
            		$("#err-info").css("display","block");
            		$("#code-err").html("图形验证码错误");
            		changeImgCode();
                }else{
                	$("#err-info").css("display","none");
                	$("#code-err").html("");
                }
            }
    	});
    	
        if(res.status != 200){
        	return false;
        }
        return true;
    }
}

function validate_smscode() {
	var res = "";
    var value = $("#sms").val();
    if(isEmpty(value)){
    	$("#err").html("短信校验码为空");
    	$("#err-info").css("display","block");
    	$("#sms-err").html("短信校验码为空");
        return false;
    }else{
    	var mobile = $("#mobile").val();
    	
    	$.ajax({
    		url: "notify/validateSmsCode?mobile="+mobile+"&code="+value,
    		data: {},
    		dataType: 'json',
    		type: "GET",
    		async:false,
    		success: function (result) {  
    			res = result;
            	if(result.status != 200){
            		$("#err").html("短信校验码错误");
            		$("#err-info").css("display","block");
            		$("#sms-err").html("短信校验码错误");
                }else{
                	$("#sms-err").html("");
                	$("#err-info").css("display","none");
                }
            }
    	});
    	
        if(res.status != 200){
        	return false;
        }
        return true;
    }
}

function validate_protocal(){
	var value = $("#protocal:checked").val();
	if(value == 1){
		return true;
	}
	zeroModal.alert("您尚未同意本网站用户协议，不能进行注册");
	return false;
}